﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Orgs;
using SmartSpace.Web;

namespace SmartSpace.WebApp.Modules.Orgs.Pages
{
    public partial class Employee_List : SsTemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Add_Employee.Enabled = true;
            this.Add_Employee.NavigateUrl = "Employee-Add.aspx";
           
            if (!IsPostBack)
            {
                BindEmployeeList();
            }
        }

        public void BindEmployeeList()
        {
            OrgsService service = new OrgsService();
            PagedList<Employee> list = service.GetEmployees("", 0, 9999);
            rep1.DataSource = list;
            rep1.DataBind();
        }

        protected void rep1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            OrgsService service = new OrgsService();
            if (e.CommandName == "Delete")
            {
                bool bl = service.DeleteEmployee(new Guid(e.CommandArgument.ToString())).IsSuccess;

                if (bl)
                {
                    Response.Redirect("Employee-List.aspx");
                }
            }
        }
    }
}